package com.itheima.controller;

import com.itheima.common.entity.Result;
import com.itheima.pojo.dto.EditNumberByOrderDateDTO;
import com.itheima.pojo.entity.OrderSetting;
import com.itheima.service.OrderSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/ordersetting")
public class OrderSettingController {

    @Autowired
    private OrderSettingService orderSettingService;

    /**
     * 导出预约报表
     * @param response
     */
    @GetMapping("/download")
    public void downloadOrderSetting(HttpServletResponse response){
        orderSettingService.download(response);
    }

    @PostMapping("/editNumberByOrderDate")
    public Result editNumberByOrderDate(@RequestBody EditNumberByOrderDateDTO editNumberByOrderDateDTO){
        orderSettingService.editNumberByOrderDate(editNumberByOrderDateDTO);
        return new Result(true,"预约设置成功");
    }

    @GetMapping("/getOrderSettingByMonth")
    public Result getOrderSettingByMonth(String month){
        List<OrderSetting> list = orderSettingService.getOrderSettingByMonth(month);
        return new Result(true,"获取预约设置数据成功",list);
    }

    @PostMapping("/upload")
    public Result uploadTemplate(MultipartFile excelFile){
        orderSettingService.upload(excelFile);
        return new Result(true,"预约设置成功");
    }
}
